package com.xone.collaboration.web;

import com.xone.collaboration.common.Result;
import com.xone.collaboration.common.ResultUtils;
import com.xone.collaboration.service.SketchpadService;
import com.xone.collaboration.service.vo.CreateGroupVO;
import com.xone.collaboration.service.vo.CreateSketchpadVO;
import com.xone.collaboration.service.vo.QueryGroupVO;
import com.xone.collaboration.service.vo.QuerySketchpadVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

@Component
@RestController
public class SketchController {

    @Autowired
    private SketchpadService service;

    @RequestMapping(value = "/group/add",method = RequestMethod.POST)
    public Result<Boolean> createGroup(@RequestBody CreateGroupVO createGroupVO) {
        try{
            service.createGroup(createGroupVO);
            return ResultUtils.success();
        }catch (Exception e){
            return ResultUtils.fail();
        }
    }

    @RequestMapping(value = "/sketchpad/add",method = RequestMethod.POST)
    public Result<Boolean> createSketchpad(@RequestBody CreateSketchpadVO createSketchpadVO) {
        try{
            service.createSketchpad(createSketchpadVO);
            return ResultUtils.success();
        }catch (Exception e){
            return ResultUtils.fail();
        }
    }

    @RequestMapping(value = "/sketchpad/delete",method = RequestMethod.POST)
    public Result<Boolean> deleteSketchpad(@RequestParam("sketchpadId") String sketchpadId) {
        try{
            service.deleteSketchpad(sketchpadId);
            return ResultUtils.success();
        }catch (Exception e){
            return ResultUtils.fail();
        }
    }

    @RequestMapping(value = "/group/get",method = RequestMethod.GET)
    public Result<QueryGroupVO> queryGroup(@RequestParam("groupId") String groupId) {
        try{
            return ResultUtils.success(service.queryGroup(groupId));
        }catch (Exception e){
            return ResultUtils.fail(null,e.getMessage());
        }
    }

    @RequestMapping(value = "/sketchpad/get",method = RequestMethod.GET)
    public Result<QuerySketchpadVO> querySketchpad(@RequestParam("sketchpadId") String sketchpadId) {
        try{
            return ResultUtils.success(service.querySketchpad(sketchpadId));
        }catch (Exception e){
            return ResultUtils.fail(null,e.getMessage());
        }
    }
}
